package edu.pku.se.chocolate.UI.View;

import edu.pku.se.chocolate.ChocolateActivity;
import edu.pku.se.chocolate.R;
import edu.pku.se.chocolate.UI.Adapter.FavoritesListAdapter;
import android.view.Gravity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ExpandableListView.OnGroupExpandListener;
import android.widget.ExpandableListView;
import android.widget.TextView;

public class FavoritesView extends ChocolateView{
	
	private ExpandableListView elv;
	private FavoritesListAdapter ila;
//	int itimes = 4;
	
	public FavoritesView(View self)
	{
		super(self);
		TextView topv = (TextView)self.findViewById(R.id.ftv);
		topv.setGravity(Gravity.CENTER);
		topv.setTextColor(android.graphics.Color.BLACK);
		elv = (ExpandableListView)this.self.findViewById(R.id.fexpandableListView);
		ila =  new FavoritesListAdapter(mainActivity, self, this);
		elv.setAdapter(ila);
		int screenWidth = ChocolateActivity.DM.widthPixels;
		elv.setIndicatorBounds((screenWidth-(screenWidth*45)/480), screenWidth);
		elv.setOnGroupExpandListener(new OnGroupExpandListener(){

			@Override
			public void onGroupExpand(int arg0) {
				// TODO Auto-generated method stub
				for(int i=0;i<ila.getGroupCount();i++) {
					if(arg0!=i)
						elv.collapseGroup(i);
				}
			}
			
		});
		init();
	}
	
	private void init()
	{
		elv.setOnItemClickListener(new OnItemClickListener(){

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				elv.expandGroup(arg2);
			}
			
		});
	}
	
	public void show()
	{
		ChocolateActivity.c_solver.setautoReflash(null,null);
		ila = new FavoritesListAdapter(mainActivity, self, this);
		elv.setAdapter(ila);
		super.show();
	}
}
